<?php
/**
 * 这个示例来演示__clone方法
 * User: ford
 * Date: 15-6-18
 * Time: 上午10:32
 */

class CloneTest {
	protected $members;
	protected $copies;

	function __construct($member, $copy = 0) {
		echo 'Now construct the object...<br />';
		$this->members = $member;
		$this->copies = $copy;
	}

	function __destruct() {
		echo 'Destroying object' . $this->members . '<br />';
	}

	function getCopies() {
		echo 'Object ' . $this->members .' has ' . $this->copies . ' copies. <br />';
	}

	function __clone() {
		$this->members .= ':CLONE';
		$this->copies++;
	}

}

$x = new CloneTest('Object One');
$x->getCopies();

$y = new CloneTest('Object Two');
$x = clone $y;		//以clone $y变量的方式更新$x变量，执行此操作不会触发构造方法
$x->getCopies();
$y->getCopies();

echo 'End of the script, executing destructor(s).<br />';
